package comm;

import java.util.Arrays;

/**
 * A container class for messages. Format of body is determined by sender.
 */
public class Message {
	public enum MessageType {
		ARRIVE, COST_REQUEST, CONFIRM, COST, FORCE_POINT, SET_VEL, VEL, ONTHEWAY, CHECKUP, COORDINATES
	}

	private MessageType type;
	private String sender;
	private Object[] body;
	private double xCoordinate;
	private double yCoordinate;

	public Message(MessageType t, String from, Object[] o) {
		type = t;
		sender = from;
		body = o;
	}

	// Separate constructor for global messages, no sender
	public Message(MessageType t, Object[] o) {
		type = t;
		body = o;
	}
	
	public Message(MessageType t, String from, double x, double y)
	{
		type = t;
		sender = from;
		xCoordinate = x;
		yCoordinate = y;
	}

	public MessageType getType() {
		return type;
	}

	public String getSender() {
		return sender;
	}
	
	public double getCoordinateX(){
		return xCoordinate;
	}
	
	public double getCoordinateY(){
		return yCoordinate;
	}

	// For retrieving a piece of information
	public Object getArg(int index) {
		return body[index];
	}

	public String toString() {
		String s = "message type=" + type.toString() + "; ";
		s += "from=" + sender + "; ";
		s += "body=" + Arrays.toString(body) + "; ";
		return s;
	}
}
